package Demo2;

public class Computer {

   public  void powerOn(){
       System.out.println("开机中，请稍后........");
   }

   public void powerOff(){
       System.out.println("关机中........");
   }

   //参数使用共用的接口IUsb类型
   public void useComputer(IUsb iUsb){
       //判断iUsb具体指向哪一个类
       //使用关键字instanceof
       //1.接入鼠标
       if(iUsb instanceof Mouse){
           //向下转型
           Mouse mouse = (Mouse) iUsb;
           //接入IUsb接口
           mouse.openDevice();
           //使用鼠标
           mouse.click();
           //退出IUsb接口
           mouse.closeDevice();
       }
       //2.接入键盘
       if(iUsb instanceof KeyBoard){
           //向下转型
           KeyBoard keyBoard = (KeyBoard) iUsb;
           //使用IUsb接口
           keyBoard.openDevice();
           //使用键盘
           keyBoard.useKeyBoard();
           //退出IUsb接口
           keyBoard.closeDevice();
       }
   }
}
